package com.eastfair.pay.chinaums.common;


import com.eastfair.pay.chinaums.common.utils.OpenHttpClient;
import com.eastfair.pay.chinaums.common.utils.ParamUtil;
import com.eastfair.pay.chinaums.common.utils.SignUtil;
import com.eastfair.pay.chinaums.common.utils.TimeUtil;

/**
 * @author yuntu
 * @description 通用接口demo，获取token
 * @date 2020/6/9
 */
public class GetToken {
    public static void main(String[] args) {
        //todo 修改为开放平台提供的appid和key
        String appid ="8a81c1bd831e4c960187c2110cae4a9f";//测试环境相关AppId
        String appkey="b8f748d264574ce68a389054e4152213";//测试环境对应key
        String timestamp = TimeUtil.getTimestamp();
        String nonce ="898350579918007";
        String body;
        String url = "https://api-mop.chinaums.com/v1/token/access";
        System.out.println("url:\n"+url);
        String sign = SignUtil.getSHA1(appid+timestamp+nonce+appkey);
        System.out.println("sign:\n"+sign);
        body = ParamUtil.buildTokenParam(appid,timestamp,nonce,sign);
        System.out.println("body:\n"+body);
        String response = OpenHttpClient.request(url, body);
        System.out.println("response:\n"+response);
    }
}
